package clientGUI;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.UIManager;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;

public class ConnectionGUI {

	private JFrame frame;
	private JTextField txtIP;
	private JTextField textFieldPort;
	public static User user;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try 
				{
					UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
					ConnectionGUI window = new ConnectionGUI();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public ConnectionGUI() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setResizable(false);
		frame.setBounds(100, 100, 438, 75);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JLabel lblIp = new JLabel("IP:");
		lblIp.setBounds(12, 13, 56, 16);
		frame.getContentPane().add(lblIp);
		
		txtIP = new JTextField();
		txtIP.setText("localhost");
		txtIP.setBounds(35, 10, 106, 22);
		frame.getContentPane().add(txtIP);
		txtIP.setColumns(10);
		
		textFieldPort = new JTextField();
		textFieldPort.setText("5555");
		textFieldPort.setBounds(188, 10, 116, 22);
		frame.getContentPane().add(textFieldPort);
		textFieldPort.setColumns(10);
		
		JLabel lblPort = new JLabel("Port:");
		lblPort.setBounds(153, 13, 56, 16);
		frame.getContentPane().add(lblPort);
		
		JButton btnNewButton = new JButton("Connect");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try 
				{
					MainGUI main=new MainGUI(txtIP.getText(),Integer.parseInt(textFieldPort.getText()));
					main.frame.setVisible(true);
					frame.setVisible(false);
				} catch (IOException e) 
				{
					JOptionPane.showMessageDialog(new JFrame(),	"ERROR - Connection refused!","Error",JOptionPane.ERROR_MESSAGE);
					System.exit(1);
					e.printStackTrace();
				}
			}
		});
		btnNewButton.setBounds(316, 9, 104, 25);
		frame.getContentPane().add(btnNewButton);
	}
}


